package com.sskj.hhrt.market;

import com.hjq.toast.ToastUtils;
import com.sskj.base.utils.RxUtils;
import com.sskj.hhrt.BasePresenter;
import com.sskj.hhrt.api.Api;
import com.sskj.hhrt.api.ApiObserver;
import com.sskj.hhrt.market.bean.MarketData;
import com.sskj.hhrt.message.data.MessageData;

import java.util.List;

public class MarketSearchListPresenter extends BasePresenter<MarketSearchListActivity> {
    public void getNoticeList(String code, boolean showLoading) {
        Api.getInstance().searchMarketList(code)
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<List<MarketData>>(this, showLoading) {
                    @Override
                    public void onSuccess(List<MarketData> data) {
                        mView.setData(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        mView.setData(null);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.finishRefresh();
                    }
                });
    }

    //添加自选
    public void addOptional(String code, boolean showLoading) {
        Api.getInstance().addOptional(code)
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<Object>(this, showLoading) {
                    @Override
                    public void onSuccess(Object data) {
                        ToastUtils.show("添加成功");
                    }

                });
    }
}
